約 6,019,323 件
https://w.atwiki.jp/androidkensyu/pages/13.html
Android 近年普及が進んでいるスマートフォン向けプラットフォーム。OS、ミドルウェア、主要アプリケーションからなるソフトウェアスタック。
https://w.atwiki.jp/android/pages/21.html
Hello, Android! 第一印象は重要だ。それは、あなたが、このアンドロイドというフレームワークを手にして、"Hello, World!"を書いたときに受ける第一印象だ。そう、アンドロイドにおいて、それはとても簡単なのだ。下記を見て欲しい。 プロジェクトを作成する。 UIを構築する。 コードを走らせる Hello, Android 以下のセクションでそれをつまびらかに語っていこう。 UIをXMLのレイアウトにアップグレードする。 プロジェクトをデバッグする。 Eclipseなしでプロジェクトを作成する。 さあ行こう。 プロジェクトを作成する プロジェクトを作成することはできる限り簡単にしてある。Eclipseプラグインで、Androidの開発環境のスナップを作成することが可能だ。Eclipse 3.3以上(Europa)と、Eclipse用のAndroidプラグインは用意してあるかい?それらをインストールしてから次に進んで欲しい。 最初に、"Hello, World!"をビルドするための、簡単な要約を述べておこう。 File- New- Project menuから、"Android Project"を新しく作成する。 New Android Project ダイアログで、プロジェクトの詳細を埋める。 なにかを表示するための自動生成されたテンプレートコードを編集する。 さあ、行こう!以下でそれぞれのステップの詳細を説明しよう。 1.新しい"Android Project"を作成する。 Eclipseから、File- New- Projectと選択して欲しい。もし、EclipseのAndroidプラグインがきちんとインストールされているなら、表示されるダイアログの中に、"Android"と名前のついたフォルダがあり、その中には、"Android Project"があるはずだ。 "Android Project"を選択し、"Next"を押そう。 2.New Android Project ダイアログで、プロジェクトの詳細を埋める。 次の画面で、プロジェクトに関係する詳細を入力する。たとえば次の例のように: それぞれの入力欄が意味するところは次のようになる。 Project Name プロジェクトを保存したいディレクトリもしくはフォルダの名前 Package Name これはパッケージの名前空間だ。ちょうどJavaのように。あなたのソースコードは全てここより下位におかれるようにする。ここには、自動生成されたスタブのパッケージ名がすでにセットされているはずだ。パッケージ名は、システムにインストールされるすべてのパッケージ間で、ユニークである必要がる。というわけで、あなたのアプリケーションに標準的なドメイン命名スタイルを使うことはとても重要だ。上述の例では、パッケージ名として、ドメイン"com.google.android"を使用している。あなたの所属する組織にみあった、唯一の名前を使用するといいだろう。 Activity Name ここでは、プラグインによって生成されるスタブクラスの名前が書かれている。これは、AndroidのActivityクラスのサブクラスである。Activityは単純なクラスで、それ自体で実行させ、処理させることができる。希望するならUIも作れるが、そうしなくても構わない Application Name ここにはユーザーが目にするアプリケーションのタイトルを入力する。 "Use default location"チェックボックスをONにすることで、プロジェクトファイルの保存場所を変更することができる。 3.自動生成コードを編集する。 After the plugin runs, you ll have a class named HelloAndroid that looks like this プラグインを実行すると、下記のような、HelloAndroidクラスが出来上がっているがわかるだろう。 public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); } } 次のステップで、これを修正していこう! UIを構築する。 プロジェクトをセットアップしたあとは、当然、それを修正していく。以下がその完成品だ。1行ずつ解剖していこう。 public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); TextView tv = new TextView(this); tv.setText("Hello, Android"); setContentView(tv); } } このサンプルのコンパイルをするために、インポートセクションに、"import android.widget.TextView;"を追加するしなければらいことを注意しよう。 Androidでは、ユーザーインターフェースは、Viewsと呼ばれるクラス階層で成り立っている。Viewはシンプルな描画オブジェクトである。たとえば、ラジオボタンであるとか、アニメーションであるとか、(今回のケースは)テキストラベルなどだ。テキストを扱えるVieewのサブクラスの名前は、単に、TextViewとなる。 下記が、TextViewクラスを生成する方法だ。 TextView tv = new TextView(this); TextViewクラスのコンストラクタに渡している引数は、Android Contextのインスタンスである。Contextは単にシステムへ渡すハンドルである。そのハンドルは、リソースを解決したり、データベースや設定などにアクセスするために供給されている。ActivityクラスはContextから派生している。それゆえ、HelloAndroidクラスはActivityクラスのサブクラスであり、コンテキストであるのだ。だから、"this"参照をTextViewに渡すことができる。 一度TextViewを生成してしまえば、何を表示するのか伝えてあげる必要がある。 tv.setText("Hello, Android"); とくに特筆すべきことはないだろう。 ここまでで、TextViewを生成し、どんなテキストをディスプレイに表示すべきかを伝えた。最後のステップは、実際のディスプレイに、TextViewをつなぐことである。こんな感じに。 setContentView(tv); ActivityのsetContentViewメソッドは、ActivityのUIにどのViewが関連付けられるべきかをシステムに通知する。もし、Activityがこのメソッドをコールしないなら、UIは何も表示されないし、システムは真っ白けの画面を表示することだろう。今のところの目的は、何でもいいからテキストを表示することなので、作ったばかりのTextViewを渡してしまえばよい。 これで、アンドロイドでの"Hello, World"のコーディングは完了だ。もちろん、つぎは、実行させるてみよう。 コードの実行 Hello, Android Eclipseプラグインのおかげで、とても簡単にあなたのアプリケーションを実行することができる。メニューからRunを選択すると、下のようなダイアログが表示される。 次に、"Android Application"を選択しよう。そして、アイコンの左上をクリックしよう(+印とともに、画面に描画されているやつだ)。それとも、単に、"Android Application"をダブルクリックするだけでいい。"New_configuration"と名づけられた新しいランチャーダイアログが表示されるはずだ。 名前を何か適当なもの、たとえば、"Hello, Android"と変更して、"Browse"ボタンを押下して、あなたのプロジェクトを選択しよう。(もしあなたが2個以上のAndroidプロジェクトをEclipseで開いていたら、正しいものを選択しているかどうか確かめてほしい)プラグインは、自動的に、あなたのプロジェクトからActivityのサブクラスをスキャンして、"Activity "ラベルの下のドロップダウンリストに追加してくれる。デフォルトでは、あなたは、"Hello, Android"プロジェクトしか作っていないから、単に続けるだけでいい。 "Apply"ボタンを押下しよう。こういう風になる。 これで成功だ。"Run"ボタンを押してみよう。Androidエミュレータがスタートするはずだ。起動完了したら、あなたのアプリケーションが表示されるだろう。今までいったことが全部できていれば、次のような画面を目にすることができるはずだ。 これが、Androidにおける、"Hello, World"だ。とっても簡単だったろう?チュートリアルの次のセクションでは、Androidについて、より詳細な価値ある情報を知ることができるだろう。 UIをXMLレイアウトにアップグレードする。 さっき終わらせた。"Hello, World"サンプルは、いわゆる"programmatic"なUIレイアウトだ。このことは、UI記述をソースコードに直接書いてビルドしているってことだ。UIプログラミングがおわっても、変更にもろいやりかただってことはわかるだろう。たとえば、ちょっとしたUIのレイアウトの変更が、大きなソースコードの変更につながったりとか。Viewクラス同士のつながりは忘れやすいし、それがデバッグに時間を浪費することにつながる。 そんなわけで、Androidでは、もうひとつのUI構築のモデルを提供している。それが、XMLベースのレイアウトファイルだ。このコンセプトを説明するには一例をあげるのが一番だね。ここに、今終わらせたプログラミングベースのものと同じ振る舞いをするXMLレイアウトファイルを用意しよう。 ?xml version="1.0" encoding="utf-8"? TextView xmlns android="http //schemas.android.com/apk/res/android" android layout_width="fill_parent" android layout_height="fill_parent" android text="Hello, Android"/ たいていの、Andorid XMLレイアウトファイルの構成はシンプルだ。タグのツリーからなっており、それぞれのタグは、Viewクラスの名前になっている。この例で言えば、TextView一要素だけからなる シンプルなツリー構成だ。XMLレイアウトファイルには、タグ名として、Viewクラスを継承したものなら、自作のものでも何でも使える。これは、Webの構築モデルからインスパイアされたものなんだ。ちょうど、UIの表示とデータを処理するアプリケーションロジックを分離できるみたいに。 この例では、4つのXML属性がある。以下が、その意味の要約だ。 Attribute 意味 xmlns android XMLネームスペース定義だ。これは、Androidネームスペースで定義された、共通の属性を参照するということをAndroidツールに知らせている。 android layout_width この要素は、このViewが消費する画面幅がどれくらいなのかを定義する要素だ。この場合で言えば、"fill_parent"を使っているが、画面全体の幅を指定しているってことになる。 android layout_height android layout_widthto同じようなものだが、これは高さを意味する。 android text これは、TextViewの内容をセットするものだ。この例でいえば、いつもの"Hello, Android"だ。 そう。XMLレイアウトはざっとこんな感じだ。けど、どうやってそれを組み込むと思う? resディレクトリの下に入れればOKだ。"res"は"resources"をはしょったもので、そのディレクトリには、アプリケーションに必要なコード以外の一式を詰め込んでおけばいい。たとえば、イメージや、ローカライズされた文字列や、XMLレイアウトファイルだ。 Eclipseプラグインは、XMLファイルを作成してくれる。上の例では単にそれを使わなかっただけだ。Package Explorerで、resフォルダの内容を開いて、main.xmlファイルに編集して、上のテキストをコピーして、変更を保存しよう。 Package Explorerのソースコードフォルダから、R.javaファイルを開いてみよう。次のようなものが表示されるはずだ。 public final class R { public static final class attr { }; public static final class drawable { public static final int icon=0x7f020000; }; public static final class layout { public static final int main=0x7f030000; }; public static final class string { public static final int app_name=0x7f040000; }; }; プロジェクトのR.javaファイルに全てのリソースにインデックスが定義されている。このクラスをソースコードのなかで、プロジェクトで使用しているリソースへの参照の速記方法の一つとしてつかえばいい。これはEclipseのようなコードコンプリート機能を持つIDEでは特にパワフルだ。なぜなら、その機能のおかげで、すばやく、インタラクティブに探しているリソース参照を配置することができるからだ。 この例で注意すべきは、"layout"と命名されたインナークラスと、"main"と命名されたフィールドだ。新しいXMLレイアウトファイルを追加したら、エクリプスプラグインは通知し、R.javaファイルを再生成するだろう。つまり、他のリソースファイルをプロジェクトに追加するなら、R.javaファイルも更新されるのがわかるだろう。 最後に、あなたのHelloAndroidコードを、ハードコーディングされたバージョンからXMLのUIを使うように修正する必要がある。新しいクラスはこのようになるはずだ。見ればわかるように、ソースコードはよりシンプルになった。 public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); } } この変更を加える際に、コピーアンドペーストをしないことだ。Rクラスに働くコードコンプリート機能を試してみよう。これがかなり使える機能だってことがわかるだろう。 変更を加えたら、アプリケーションを再起動してみよう。することと言えば、緑のRunと書かれた矢印アイコンをクリックし、Run - Run Last Launchedをメニューから選択するだけだ。すると、さっき見たのと同じものが表示されるはずだ!結局のところ、2つの違ったレイアウトのアプローチは同じ結果をもたらすわけだ。 XMLレイアウトの作成はもっと説明することがあるんだが、今ここで説明してもしょうがない。このアプローチのもっと詳細な情報のためには"Implementing a Uset Interface"ドキュメントを読んで欲しい。 プロジェクトのデバッグ EclipseのAndroidプラグインは、Eclipseデバッガにうまく統合されてもいる。それをデモするために、コードにバグを混入させてみよう。次のようにHelloAndroidのソースコードに変更を入れて欲しい。 public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); Object o = null; o.toString(); setContentView(R.layout.main); } } これは単に、NullPointerExceptionを入れてみただけだ。もう一度アプリケーションを実行させると、すぐに次のような画面を見るだろう。 何がおかしかったのかを特定するために、ソースコードの"Object o = null;"と書かれた行にブレークを貼ってみよう。(ブレークポイントを貼るためには、Eclipseの行番号の左の領域をダブルクリックすればいい)それから、Run - Debug Last Launched を選択してデバッグモードに入ろう。エミュレータが再起動すると、セットしたブレークに到達した時点でアプリケーションは中断する。EclipseのDebug Perspectiveを通してどんなアプリケーションでもステップ実行ができる。 Eclipseなしでプロジェクトを作成する。 もし、あなたがEclipseを使用しないなら(たとえば別のIDEがいいだとか、そもそも単にテキストエディタとコマンドラインツールが使いたいなら)Eclipseプラグインはあなたの助けにはならないだろう。でも心配しなくていい。Eclipseを使用しないからといって、あなたは何も便利さを失わないのだ。 EclipseのAndroidプラグインは、Android SDKに同梱されているツール群のラッパーにすぎないからだ。(ツール群とは、エミュレータや、aapt,adb,ddmsなどだ。ほかにもどこかにドキュメントがあるだろう)それゆえ、他のツールを使って、それらをラッピングすることは可能だ。たとえば ant のビルドファイルを使うなどして。 Android SDKは、"activityCreator.py"とネーミングされたPythonスクリプトも含んでいる。それは、antと互換性のあるbuild.xmlファイルはもちろんプロジェクトに必要なソースコードとスタブディレクトリを全て作成してくれる。これは、コマンドラインでプロジェクトをビルドできることと、あなたの好きな他のIDEと統合できることを意味する。 たとえば、Eclipseを通してさっき作ったものと似たようなHelloAndroidプロジェクトを作成するためには、次のコマンドを使えばいい。 activityCreator.py --out HelloAndroid com.google.android.hello.HelloAndroid プロジェクトをビルドするためには、 ant コマンドを走らせればいい。コマンドが成功すれば、 bin フォルダの下にHelloAndroid.apkと名づけられたがファイルがあるはずだ。この.apkファイルは、Android Packageで、 adb ツールを使ってエミュレータにインストールして実行できる。 これらのツールについての使用方法をもっと知りたければ、上で紹介されたドキュメントを読んで欲しい。
https://w.atwiki.jp/android/pages/43.html
チュートリアル:ノートパッドエクササイズ1 本エクササイズではシンプルなノートリストを作ります。このノートリストを使ってユーザは新規ノートを追加することができますが、ノートの編集を行うことはできません。本エクササイズでは以下の事項をデモンストレートします。 ListActivities の基本、メニューオプションの作成・操作の基本 SQLite データベース内のノートへのアクセス/保存方法 ArrayAdapter (ListView にバインドするためのもっともシンプルな方法の一つ)を用いてデータを ListView にバインドする方法 リストビューの配置の仕方やアクティビティメニューへのアイテムの追加のやり方、アクティビティがアクティビティメニューアイテムをどのように扱うか、といったスクリーンレイアウトの基本 [エクササイズ1] [エクササイズ2?] [エクササイズ3?] [追加事項?] Step 1 Notepadv1 プロジェクトを開きます。 Notepadv1 は開始点として提供されるプロジェクトです - it takes care of some of the boilerplate work that you have already seen if you followed the Hello Android tutorial (すでにHello Android(もしもしアンドロイド)のチュートリアルで見ているかもしれませんが、共通する説明があります。) 2. browse ボタンを押し、あなたが本エクササイズをコピーしたフォルダを選択し、その中からNotepadv1を選んでOKを押してください。 a. Package Explorer で右クリックし、New- Project... を選択してください。 b. Android/Android Project を選択し、Next を押してください。 c. New Android Project のダイアログで、Create project from existing source(既存のソースからプロジェクトを作成)を選択してください. d. browse ボタンを押し、あなたが本エクササイズをコピーしたフォルダを選択し、その中からNotepadv1を選んでOKを押してください。 e. Project name 欄に Notepadv1、Location 欄に選択したパスが表示されることを確認してください。 f. Finish を押します。 g. 本エクササイズのプロジェクトが Eclipse の Package Explorer に開かれ準備が完了します。 h. もし AndroidManifest.xml にエラー表示が出ていたり、Android の zipファイルに関連する問題が表示された場合は、プロジェクトの上で右クリックし、ポップアップから、Android Tools- Fix Project Properties を選択してください。(プロジェクトがライブラリの場所を正しく見ていないので、この操作でそれを修復します。) Step 2 データへのアクセスと更新について このエクササイズにおいては、単にSQLiteデータベースを直接使ってデータを保存しますが、実際のアプリケーションでは正当なContentProviderを作成し、処理をカプセル化する方がずっと良いでしょう。 もし興味があれば、content provider やデータの保存/検索/表示などに関する情報をいろいろと見つけることが出来るでしょう。 DBHelper クラスを見てみてください - このクラスは、我々が作成するノートのデータを保持するとともにその更新も可能にする、SQLiteへのデータアクセスをカプセル化するために提供されています。 典型的にはContentProviderを用いることでこのクラスを実装します。そして実際、SDKには行っている完全なNotepadアプリケーションはそのようなContentProviderを実装しています。しかし、我々がこれからするように、単にSQLiteデータベースを直接利用していけない理由はありません。このクラスについて注意すべき重要なことは、それがSQLiteデータベースのデータの保存、参照、更新の詳細の面倒をみてくれるということです。全ての行を取得するメソッド、行IDに基づいて行を取得するメソッド、新しい行を作成するメソッド、既存の行を削除するメソッド、既存の行を更新するメソッドがあります。もしあなた自身のアプリケーションでSQLiteデータベースを利用する方法に関する入門を希望なら、このクラスを見てみるか、より良くは、ContentProviderの利用例として SDK の samples/ ディレクトリに入っている完全なNotepadアプリケーションを見てみてください。 Step 3 Layout と activity とについて ほとんどのActivityはそれに関連付けられたレイアウトを持っています。レイアウトはユーザに対してそのactivityの「顔」となります。今回の例では我々のレイアウトは画面全体を覆いノートの一覧を提供します。 しかし、フルスクリーンレイアウトはActivityにとっての唯一の選択肢ではありません。フローティングレイアウト(たとえばダイアログとか警告のように)が欲しいこともあるでしょうし、レイアウトを全く必要としないこともあるでしょう(使用するレイアウトを決めない場合、activityはユーザに見えなくなります)。 Open the notepad_list.xml file in res/layout and take a look at it This is a layout definition file with a default starting point in it, we have provided this as a convenience to get you going quickly. 1. All Android layout files must start with the XML header line ?xml version="1.0" encoding="utf-8"? . 2. Also, the next definition will often (but not always) be a layout definition of some kind, in this case a LinearLayout. 3. Note also that the xml namespace of Android should always be defined in the top level component or layout in the XML so that android tags can be used through the rest of the file xmlns android="http //schemas.android.com/apk/res/android" Step 4 We need to create the layout to hold our list. Add code inside of the LinearLayout tag so the whole file looks like this (you may have to hit the Source tab in order to edit the XML file) ?xml version="1.0" encoding="utf-8"? LinearLayout xmlns android="http //schemas.android.com/apk/res/android" android layout_width="wrap_content" android layout_height="wrap_content" ListView id="@id/android list" android layout_width="wrap_content" android layout_height="wrap_content"/ TextView id="@id/android empty" android layout_width="wrap_content" android layout_height="wrap_content" android text="@string/no_notes"/ /LinearLayout 1. The ListView and TextView can be thought as two alternative views, only one of which will be displayed at once. ListView will be used when there are notes to be shown, while the TextView (which has a default value of "No Notes Yet!" defined as a string resource, will be displayed if there aren t any notes to display). 2. The @ in the id strings of the ListView and TextView means that the XML parser should parse and expand the rest of the id string and use an ID resource. 3. And, the android list and android empty are IDs that are already provided for us by the Android platform, empty is used automatically when no data is provided in the list adapter. The List Adapter knows to look for these names specifically by default. Alternatively you could also choose to change the default empty view used by the List Adapter by using the setEmptyView(). More broadly, the android.R class is a set of predefined resources provided for you by the platform, while your project s R class is the set of resources your project has defined. Resources found in the android.R resource class can be used in the XML files by using the android name space prefix (as we see here). Step 5 Resources and the R class The folders under res/ in the Eclipse project are special. There is a specific structure to the folders and files under this folder. In particular, resources defined in these folders and files will have corresponding entries in the R class allowing them to be easily accessed and used from your application. Furthermore, they will be bundled and deployed as part of the application. To make a list view, we also need to define a view for each row in the list 1. Create a new file under res/layout called notes_row.xml. 2. Add the following contents (note again the xml header is used, and the first node defines the Android xml namespace) ?xml version="1.0" encoding="utf-8"? TextView id="@+id/text1" xmlns android="http //schemas.android.com/apk/res/android" android layout_width="wrap_content" android layout_height="wrap_content"/ 3. This is the view that will be used for each notes title row — it has only one text field in it. 4. In this case we create a new id called text1. The + after the @ in the id string indicates that the id should be automatically created if it does not already exist, so we are defining text1 on the fly and then using it. 5. After saving this file, open the R.java class in the project and look at it, you should see new definitions for notes_row and text1 (our new definitions) meaning we can now gain access to these from the our code. Step 6 Next, open the Notepadv1 class in the source. We are going to alter this class to become a list adapter and display our notes, and also allow us to add new notes Notepadv1 will be a subclass of Activity called a ListActivity, which has extra functionality to accommodate the kinds of things you might want to do with a list, for example displaying an arbitrary number of list items in rows on the screen, moving through the list items, and allowing them to be selected. Take a look through the existing code in Notepadv1 class. There are some constant definitions at the top, followed by a private field we will use to create numbered note titles, and some overrides of methods from the superclass. Step 7 Change the inheritance of Notepadv1 from Activity to ListActivity public class Notepadv1 extends ListActivity Note you will have to import ListActivity into the Notepadv1 class using Eclipse, ctrl-shift-O on Windows or Linux, or cmd-shift-O on the Mac (organize imports) will do this for you. Step 8 There are already three override methods defined onCreate, onCreateOptionsMenu and onOptionsItemSelected, we need to fill these out * onCreate() is called when the activity is started — it is a little like the "main" method for the activity. We use this to set up resources and state for the activity when it is running * onCreateOptionsMenu() is used to populate the menu for the activity. This is shown when the user hits the menu button, and has a list of options they can select (like "Create Note") * onOptionsItemSelected() is the other half of the menu equation, it is used to handle events generated from the menu (e.g. when the user selects the "Create Note" item). Step 9 Fill out the body of the onCreate() method. Here we will set the title for the activity (shown at the top of the screen), use the notepad_list layout we have created for the activity display contents, set up the DBHelper instance we will use to access notes data, then populate the list with the available note titles 1. call super() with the icicle parameter passed into our method 2. setContentView to R.layout.notepad_list 3. Create a new private class field called dbHelper of class DBHelper (before the onCreate method) 4. Back in the onCreate method, construct a DBHelper instance — assign to the dbHelper field (note, you must pass this into the constructor for DBHelper) 5. Finally, call a new method -fillData()- gets the data and populates it using the helper, we haven t defined it yet 6. onCreate() should now look like this @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.notepad_list); dbHelper = new DBHelper(this); fillData(); } And remember to add the DBHelper field definition (right under the noteNumber definition) private DBHelper dbHelper; Step 10 More on menus The notepad application we are constructing only scratches the surface with menus. You can also add shortcut keys for menu items, create submenus and even add menu items to other applications!. Fill out the body of the onCreateOptionsMenu() method. We are going to add just one menu item for now, "Add Item", using a string we will create in strings.xml, and defined with a constant we will create at the top of the class to identify the Add Item operation. 1. In strings.xml resource (under res/values), add a new string for menu_insert with text "Add Item" string name="menu_insert" Add Item /string , then save the file 2. Also, you need a menu position constant at the top of the Notepadv1 class (right under the KEY_BODY definition) public static final int INSERT_ID = Menu.FIRST; 3. In the onCreateOptionsMenu() method, add the menu item. Also take care of the result of the super call being returned. The whole method should now look like this @Override public boolean onCreateOptionsMenu(Menu menu) { boolean result = super.onCreateOptionsMenu(menu); menu.add(0, INSERT_ID, R.string.menu_insert); return result; } Step 11 Fill out the body of the onOptionsItemSelected() method This is going to handle our new "Add Note" menu item. When this is selected the onOptionsItemSelected() method will be called with the item.getId() set to INSERT_ID (the constant we used to identify the menu item). We can detect this, and take the appropriate actions 1. The super.onOptionsItemSelected(item) method call goes at the end of this method — we want to catch our events first! 2. Switch statement on item.getId() 3. case INSERT_ID 4. calls new method createNote() 5. break at the end of the case 6. return the result of the superclass onOptionsItemSelected() method at the end 7. The whole onOptionsItemSelect() method should now look like this @Override public boolean onOptionsItemSelected(Item item) { switch (item.getId()) { case INSERT_ID createNote(); break; } return super.onOptionsItemSelected(item); } Step 12 Add a new createNote() method In this first version of our application, createNote() is not going to be very useful. We will simply create a new note with a title assigned to it based on a counter ("Note 1", "Note 2"...) and with an empty body. At present we have no way of editing the contents of a note, so for now we will have to be content making one with some default values 1. String noteName = "Note " + noteNumber++; (Construct the name using "Note" and the counter we have defined in the class) 2. Call dbHelper.createRow() using noteName as the title and "" for the body 3. Call fillData() method again after adding (inefficient but simple) 4. The whole createNote() method should look like this private void createNote() { String noteName = "Note " + noteNumber++; dbHelper.createRow(noteName, ""); fillData(); } Step 13 List adapters Our example uses a very simple array adapter which binds an array or list of items into a ListView. More commonly in Android, List Adapters go hand in hand with ContentProviders, and this is also a very easy way to use lists. To bind a ContentProvider to a ListView you can use a android.widget.SimpleCursorAdapter to bind data from a ContentProvider into a ListView Define the fillData() method. This is fairly long This method uses ArrayAdapter, which is the simplest way of putting data into a ListView. ArrayAdapter takes either a List or an array of Strings, and binds them into a text view provided in the layout defined for the list row (this is the text1 field in our notes_row.xml layout). The method simply obtains a list of notes from the database helper, constructs a List of Strings using the title strings from each row, and then creates an ArrayAdapter out of those items and bound to use the notes_row we defined. private void fillData() { // We need a list of strings for the list items List String items = new ArrayList String (); // Get all of the rows from the database and create the item list List Row rows = dbHelper.fetchAllRows(); for (Row row rows) { items.add(row.title); } // Now create an array adapter and set it to display using our row ArrayAdapter String notes = new ArrayAdapter String (this, R.layout.notes_row, items); setListAdapter(notes); } 1. ArrayAdapter needs a List of Strings (List String ) containing the items to display 2. The data is read out of the database as rows, and the title field from each row is used to populate the list of strings 3. We specify the notes_row view we created as the receptacle for the data 4. If you get compiler errors about classes not being found, ctrl-shift-O or (cmd-shift-O on the mac) to organize imports. Note that for this exercise we use an ArrayAdapter, this is not a very scalable solution and more typically a SimpleCursorAdapter would be used with a ContentProvider or at least a Cursor returned from a query. See the sidebar on List Adapters for more information. Step 14 Run it! 1. Right click on the Notepadv1 project 2. From the popup menu, select Run As - Android Application 3. If you see a dialog come up, select Android Launcher as the way of running the application (you can also use the link near the top of the dialog to set this as your default for the workspace, this is recommended as it will stop the plugin from asking you this every time) 4. Add new notes by hitting the menu button and selecting Add Item from the menu Solution and Next Steps You can see the solution to this class in Notepadv1Solution from the zip file to compare with your own. Once you are ready, move on to Tutorial Exercise 2 to add the ability to create, edit and delete notes. Back to the Tutorial main page...
https://w.atwiki.jp/mywiki2010/pages/14.html
USBブート可能なx86マシンでAndroidを動作させる。 参考サイト一覧 「Android」をx86パソコンで動かそう ITpro 話題の携帯向けOS「Android」をx86パソコンで動かしてみよう (2009/02/27) ブログなど NWLab.com USB起動可能なAndoroid OSでPCからAndroidを起動してみました(2009/04/13) 即席USBブート環境構築(Windows編) ダウンロード可能なイメージファイルでお手軽にAndroidを動作させる。 (更新 2010/02/09) (1) 必要なものを用意 WindowsがインストールされたPC USBブート可能なPC(WindowsPCと同じでも良い) USBメモリ1GBもあれば十分。 FAT32でフォーマットしておく。 不慮の事故でデータが消えても困らないよう、大事なデータは事前にバックアップ。 (2) Androidのブート・イメージ入手 「USBブート・イメージ入手先」からファイルをダウンロードする。 (3) ブート・イメージの書き込み 書き込みソフトを使ってブート・イメージをUSBメモリに書き込む。 ソフト一覧 DDforWindowsWindowsXP, WindowsVistaで使用可。他Windowsでは未検証。 本ソフトでUSBから読み込んだディスクイメージはLinuxのddコマンドでそのまま使用可能。 (4) Android起動 Andoridを動かすPCでUSBブート可能になるようBIOSを設定するEeePC1000HEでは、PC起動時にESCキーを連打することでブート・ドライブを選択可能。 電源の入っていないPCのUSBポートにUSBメモリを差し込む 電源を入れるとAndroidが立ち上がる起動中にもUSBアクセスを行っているので、USBメモリは抜かないよう注意。 設定を変更した場合(表示言語など)は変更内容がUSBメモリに書き込まれ、次回起動時にも反映される。
https://w.atwiki.jp/sunday_notebook/pages/24.html
特徴 Androidアプリケーションは、アプリを起動するためのひとつの決まったエントリーポイントがない。 そのため以下の四つのコンポーネントで構成されている。 アクティビティ サービス ブロードキャストレシーバ コンテンツプロバイダ ひとつのアプリがこれら全てのコンポーネントを備えている必要はない。 また、同じ種類のコンポーネントを複数備えていても問題ない。 アクティビティ ユーザーインターフェイス(UI)を持った実行単位。 また全てのアクティビティはAndroidManifest.xmlに記録される。 Activityクラスのサブクラスとして定義される。 →画面の一枚一枚と考えてもいいのかな? サービス UIを持たずに、通常はバックグラウンドで継続的に動作するようなコンポーネント。 Serviceクラスのサブクラスとして定義。 →SDKのサンプルではアラームサービスに使われている。時間監視の機能などに。 ブロードキャストレシーバ システム内のブロードキャストを受信して、それに対処するコンポーネント。 BroadcastReceiverクラスのサブクラスとして定義する。 コンテンツプロバイダ ひとつのアプリが管理しているデータ(コンテンツ)を他のアプリでも使えるように提供する機能。 ContentProviderクラスのサブクラスとして定義される。
https://w.atwiki.jp/tamotech/pages/40.html
Androidアプリケーション開発 eclipse開発環境 開発に必要なプラグインをインストールする eclipseのメニュー「ヘルプ 新規ソフトウェアのインストール...」でインストールを行う。 ロケーション「https //dl-ssl.google.com/android/eclipse」でリポジトリーを追加する。名前は「Android Plugin」など、適当に。 エラーが出る場合は、「http //dl-ssl.google.com/android/eclipse」でトライしてみる価値があるらしい。 Android SDKの設定を行う eclipseのメニュー「ウィンドウ 設定...」でダイアログを開き、「Android」メニューを選択。 「SDKロケーション」にダウンロードしたandroid sdkのフォルダ(android-sdk-windows)を指定する。 Android SDK および AVD マネージャー 実機のドライバインストール とりあえず参考サイトを記録・・・ http //2dkonly.blog10.fc2.com/blog-entry-46.html
https://w.atwiki.jp/sindroid/pages/13.html
あんどろいどなぺぇじ さて何を書こうか。 アンドロイドの構成 インストールからエミュレータ起動まで (ver 2.0用 以前のバージョンだとまた違うぽい。) ここからSDKをダウンロード →解答して適当なとこに置く →パスを通す(¥toolsまで) →プロンプトからandroidと入力するとAVDマネージャ起動 →Available Packagesからインストール ・ここで何もインストールするファイルがみつからない場合がある。 /.androidにandroidtool.cfgファイル作ってsdkman.force.http=trueと入れておくと解決するはず。 ・インストールがNothingとか出たらSDKの位置変えてみる。 (C直下とか。管理者権限だとか何か知らんけどProgram Files以下に置いてたら駄目だった。) →Virtual Devicesでデバイス作成 →そこからStartで起動 SDKリファレンス 既存バグとか チップス 他
https://w.atwiki.jp/sunday_notebook/pages/17.html
メニュー 開発環境を構築する まずは必要なソフト等をインストールしよう 次にテスト環境を構築しよう 用語 Androidアプリケーションの用語あれこれ アプリ開発 ”Hello world!”〜Android〜 クラスライブラリ(jarファイル)を使う トラブル Conversion to Dalvik format failed with error 1
https://w.atwiki.jp/linuxjapanwiki/pages/74.html
Android ▲Androidロゴ Androidは、主にスマートフォンやタブレットなどの、タッチスクリーンモバイル機器向けに設計されている、Linuxカーネルやその他のオープンソースソフトウェアの改変版をベースとしたモバイルオペレーティングシステムである。 オープン・ハンドセット・アライアンスというコンソーシアムによって開発されており、主な貢献と商業的な販売はGoogleが担っている。 ▲ホーム画面 各種データ 開発者 Google LLC / オープン・ハンドセット・アライアンス /Android オープンソースプロジェクト (AOSP) 系統 Android 開発状況 開発中 初版 2008年9月23日 最新版 11 / 2020年9月8日 リポジトリ https //android.googlesource.com/ カーネル Linux ライセンス Apache License 2.0 , GNU GPL v2(カーネル)など ウェブサイト https //android.com/ 概要 Androidのコアとなるソースコードは、Androidオープンソースプロジェクト(AOSP)として知られており、主にApache Licenseの下でライセンスされている。 これによってサードパーティーによるカスタマイズが可能となり、ゲーム機、デジタルカメラ、PCなどの他の様々な電子機器向けに開発され、それぞれに特化したユーザーインターフェースを持つようになっている。 よく知られている派生製品には、テレビ用のAndroid TVやウェアラブル用のWear OSなどがあるが、これらはGoogleが開発したものである。 ソフトウェアの配布は、一般的にGoogle PlayストアやSamsung Galaxyストアのようなプロプライエタリなアプリケーションストア、またはAPK形式でソフトウェアパッケージを使用してAptoideやF-Droidのようなオープンソースのプラットフォームを介して提供されている。 Androidは、スマートフォンでは世界で最も売れているOSだが、国内ではiOSに続き2番目のシェア率となっている。 Androidには文字入力のためのIMEが搭載されていて、テキストを入力するところをタップすれば仮想キーボードが表示されるようになっている。 ただ、日本語入力用の仮想キーボードはデフォルトでは搭載されていない。日本語入力を有効にするにはサードパーティー製のIMEのインストールが必要になってくる。 Androidでは、Google Playという独自のアプリケーションインストーラが搭載されており、ユーザーはそこでアプリをインストールすることができる。 また、APKファイルから直接インストールすることもできる。ただ、Googleの認めていないアプリや悪質なアプリもあるため、注意が必要である。 リリース 主なリリースを以下に列挙する。(*1) 主なバージョン リリース日 API 2.3.3 – 2.3.7 2010年12月17日 10 4.0.3 – 4.0.4 2011年10月18日 15 4.1.x 2012年7月9日 16 4.2.x 2012年11月13日 17 4.3 2013年7月24日 18 4.4 2013年10月31日 19 5.0 2014年11月3日 21 5.1 2015年3月9日 22 6.0 2015年10月5日 23 7.0 2016年8月23日 24 7.1 2016年12月5日 25 8.0 2017年8月21日 26 8.1 2017年12月5日 27 9.0 2018年8月6日 28 10.0 2019年9月3日 29 派生OS ColorOS CyanogenMod AOKP Fire OS MIUI EMUI LeWa OS OmniROM Paranoid Android Replicant Indus OS LineageOS 外部リンク 公式ウェブサイト コメント欄 コメント欄の利用に関してはコメント欄の利用を参照して下さい。 本ページに無関係な内容のコメントは一律して削除されます。Wiki運営に関しては Wiki運営掲示板 にお願いします 。 投稿されているコメントへの返信の際は、必ず返信したいコメント横の○にチェックを入れて返信して下さい。 +上記の内容を守れる方のみご利用ください。 上記の内容を守れる方のみご利用ください。 コメントログ作成 - 名無しさん (2020-05-02 17 36 24) HarmonyOSもAndroidフォークと言われていますよね - 名無しさん (2021-06-14 21 30 53) ですね - Anonymous (2021-06-15 09 07 36) 名前 コメントログ
https://w.atwiki.jp/pcmemo/pages/25.html
Android Android SDKのインストーラにJDKが無いと言われる JDKが入っているのに 「Java SE Development Kit (JDK) not found.」 と言われる場合 64bit版WindowsだとJDKの使うレジストリの関係でインストーラがJDKを認識できないようです とりあえずzip版使えばOK 実機での実行/デバッグ 実機での実行 実機でもデバッグができるようにするEclipseならAndroid.xmlの「アプリケーション」タブからApplication Attributes内、debuggableをtrueに 直接編集する場合は、 application 要素に「android debuggable="true"」を追加 Eclipseでの実行実行やデバッグを押すとAndroid Device Chooserダイアログが出るので上側の実機デバイスを選択してOK AVDが自動で起動する場合、実行>実行(デバッグ)構成>Androidアプリケーション>(プロジェクト名)>ターゲット内のAVDのチェックを外して適用 ADBでの実機へのインストール・アンインストール 実機が繋がった状態でコマンドプロンプトから インストールadb install [.apkファイル] .apkはプロジェクトのbinフォルダにあるやつ アンインストールadb uninstall [パッケージ名] パッケージ名はcom.example~とかのやつ Android NDK ndk-build時に/cygdrive/g/David~が見つからないと言われる よくわからないけどWindowsのGドライブが関係しているようで、Daemon Toolsが作成していたGドライブを削除したら通るようになった。 参考URL https //groups.google.com/group/android-ndk/browse_thread/thread/7eb2ef515c1fca2?hl=ja